$(function() {
	changeHeaderMenu(3);
	initTable();
});

/**
 * 初始化表格数据
 */
function initTable() {
	$('#grid').grid({
		title : '',
		pager : true,
		multiSelect: false,
//		checkbox: true,
//		tbar : '#navbar',
		store : {
			url : '/cloud_ifw/member/devicelogbrow_getlist.action',
			idProperty : 'logIndex',
			uploadPagesize : 'rows'
		},
		pageCfg : {
			btnCount : 5
		},
		callback_inited: function() {
		},
		columns : [
	        {cn:'产生时间', en:'deviceExecTime', width : 100},
	        {cn:'操作类型', en:'deviceExecAction', width : 100, tpl: function(r) {
	        	var html = '';
	        	if(r.deviceExecAction == 'reboot') {
        			html = '设备重启'; 
	        	} else if(r.deviceExecAction == 'upgrade') {
        			html = '设备升级'; 
	        	} else if(r.deviceExecAction == 'upgrade_reboot') {
        			html = '设备升级并重启'; 
	        	}
	        	return html;
	        }},
	        {cn:'结果', en:'deviceExecResult',width : 100, tpl: function(r) {
	        	var html = '';
	        	if(r.deviceExecResult == 0 || r.deviceExecResult == 7 || r.deviceExecResult == 8)
	        		html = '成功';
	        	else
	        		html = '失败';
	        	return html;
	        }},
	        {cn:'描述', en:'logIndex',width : 300, tpl: function(r) {
	        	var html = '';
	        	if(r.deviceExecResult == 0) {
	        		if(r.deviceExecAction == 'reboot') {
	        			html = '设备&nbsp;' + r.deviceSn + '&nbsp;已执行重启';
	        		} else if(r.deviceExecAction == 'upgrade') {
	        			html = '设备&nbsp;' + r.deviceSn + '&nbsp;已执行升级版本&nbsp;' + r.deviceUpgradeVersion + '&nbsp;';
	        		} else if(r.deviceExecAction == 'upgrade_reboot') {
	        			html = '设备&nbsp;' + r.deviceSn + '&nbsp;已执行升级版本&nbsp;' + r.deviceUpgradeVersion + '&nbsp;并重启';
	        		}
	        	} else if(r.deviceExecResult == 1) {
	        		if(r.deviceExecAction == 'reboot') {
	        			html = '设备&nbsp;' + r.deviceSn + '&nbsp;未成功执行重启';
	        		} else if(r.deviceExecAction == 'upgrade') {
	        			html = '设备&nbsp;' + r.deviceSn + '&nbsp;未成功执行升级版本&nbsp;' + r.deviceUpgradeVersion + '&nbsp;';
	        		} else if(r.deviceExecAction == 'upgrade_reboot') {
	        			html = '设备&nbsp;' + r.deviceSn + '&nbsp;未成功执行升级版本&nbsp;' + r.deviceUpgradeVersion + '&nbsp;并重启';
	        		}
	        	} else if(r.deviceExecResult >= 2 && r.deviceExecResult <= 6) {
	        		if(r.deviceExecAction == 'reboot') {
	        			html = '下发设备&nbsp;' + r.deviceSn + '&nbsp;重启失败：';
	        		} else if(r.deviceExecAction == 'upgrade') {
	        			html = '下发设备&nbsp;' + r.deviceSn + '&nbsp;升级版本&nbsp;' + r.deviceUpgradeVersion + '&nbsp;失败：';
	        		} else if(r.deviceExecAction == 'upgrade_reboot') {
	        			html = '下发设备&nbsp;' + r.deviceSn + '&nbsp;升级版本&nbsp;' + r.deviceUpgradeVersion + '&nbsp;并重启失败：';
	        		}
	        		if(r.deviceExecResult == 2) {
	        			html += '未找到指定升级包';
		        	} else if(r.deviceExecResult == 3) {
		        		html += '固件不匹配';
		        	} else if(r.deviceExecResult == 4) {
		        		html += '未知错误';
		        	} else if(r.deviceExecResult == 5) {
		        		html += '未能成功下载升级包';
		        		html = html.substr(2);
		        	} else if(r.deviceExecResult == 6) {
		        		html += '版本相同不需要升级';
		        	}
	        	} else if(r.deviceExecResult == 7) {
	        		if(r.deviceExecAction == 'reboot') {
	        			html = '设备&nbsp;' + r.deviceSn + '&nbsp;配置了重启';
	        		} else if(r.deviceExecAction == 'upgrade') {
	        			html = '设备&nbsp;' + r.deviceSn + '&nbsp;配置了升级版本&nbsp;' + r.deviceUpgradeVersion + '&nbsp;';
	        		} else if(r.deviceExecAction == 'upgrade_reboot') {
	        			html = '设备&nbsp;' + r.deviceSn + '&nbsp;配置了升级版本&nbsp;' + r.deviceUpgradeVersion + '&nbsp;并重启';
	        		}
	        	} else if(r.deviceExecResult == 8) {
	        		if(r.deviceExecAction == 'reboot') {
	        			html = '设备&nbsp;' + r.deviceSn + '&nbsp;重启已下发';
	        		} else if(r.deviceExecAction == 'upgrade') {
	        			html = '设备&nbsp;' + r.deviceSn + '&nbsp;升级版本&nbsp;' + r.deviceUpgradeVersion + '&nbsp;已下发';
	        		} else if(r.deviceExecAction == 'upgrade_reboot') {
	        			html = '设备&nbsp;' + r.deviceSn + '&nbsp;升级版本&nbsp;' + r.deviceUpgradeVersion + '&nbsp;并重启已下发';
	        		}
	        	}
	        	return html;
	        }}
		]
	});
}